import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


public class demo3 {
    public static void main(String[] args) {
        BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();

        Thread produer = new Thread(() -> {
            while(true){
                try{
                    int n = 0;
                    queue.put(n);
                    System.out.println("生产者元素" + n);
                    n++;
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        });

        Thread consumer = new Thread(() -> {
           while(true){
               try {
                   Integer n = queue.take();
                   System.out.println("消费者元素" + n);
                   Thread.sleep(1000);
               }catch (InterruptedException e){
                   e.printStackTrace();
               }
           }
        });

        produer.start();
        consumer.start();

    }
}
